const simpleServer = require('../simple-server')
const path = require('path')
const express = require('express')
const fs = require('fs')
let folder = process.argv[2]
if (!path.isAbsolute(folder)) {
  folder = path.join(process.cwd(), folder)
}
if (fs.existsSync(folder)) {
  const app = simpleServer(3000, folder, '/download')
  app.use(express.static(path.join(__dirname, './resources')))
  app.get('/all-files', (req, res) => {
    let files = fs.readdirSync(folder)
    files = files.filter(file => !fs.statSync(path.join(folder, file)).isDirectory())
    res.json(files)
  })
} else {
  console.log(folder)
  throw new Error('文件夹路径有问题')
}
// simpleServer(3000)
//
